package com.hkts.naturalgas.alarminformation.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.alarminformation.entity.NaturalgasAlarmin;
import com.hkts.naturalgas.alarminformation.mapper.NaturalgasAlarminMapper;
import com.hkts.naturalgas.alarminformation.service.INaturalgasAlarminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2020-09-11
 */
@Service
@Transactional
public class NaturalgasAlarminServiceImpl extends ServiceImpl<NaturalgasAlarminMapper, NaturalgasAlarmin> implements INaturalgasAlarminService {


@Autowired
private NaturalgasAlarminMapper naturalgasAlarminMapper;

    @Override
    public List<Map<String, Object>> getExportData(String stationId, String grade, String id) {

        return naturalgasAlarminMapper.getExportData(stationId, grade,id);
    }

    @Override
public IPage<NaturalgasAlarmin> selectPage(Page<NaturalgasAlarmin> page, NaturalgasAlarmin naturalgasAlarmin){
        QueryWrapper<NaturalgasAlarmin> query = Wrappers.query();
        QueryWrapper<NaturalgasAlarmin> entityWrapper = getEntityWrapper(query, naturalgasAlarmin);
        return naturalgasAlarminMapper.selectPage(page, entityWrapper);
        }

    @Override
    public Page<Map<String, Object>> getJoinResult(Page page,String stationId,String grade,String id) {
        return naturalgasAlarminMapper.findJoinResult(page,stationId,grade,id);
    }

    @Override
public List<NaturalgasAlarmin> selectList(NaturalgasAlarmin naturalgasAlarmin){
        QueryWrapper<NaturalgasAlarmin> query = Wrappers.query();
        QueryWrapper<NaturalgasAlarmin> entityWrapper = getEntityWrapper(query, naturalgasAlarmin);
        return naturalgasAlarminMapper.selectList(entityWrapper);
        }

/**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<NaturalgasAlarmin> getEntityWrapper(QueryWrapper<NaturalgasAlarmin> entityWrapper,NaturalgasAlarmin naturalgasAlarmin){
        //条件拼接

                if(StringUtils.isNotBlank(naturalgasAlarmin.getEquipmentId())){
                entityWrapper.like(NaturalgasAlarmin.EQUIPMENT_ID,naturalgasAlarmin.getEquipmentId());
                }
                if(StringUtils.isNotBlank(naturalgasAlarmin.getGrade())){
                entityWrapper.like(NaturalgasAlarmin.GRADE,naturalgasAlarmin.getGrade());
                }
                if(StringUtils.isNotBlank(naturalgasAlarmin.getStationId())){
                entityWrapper.like(NaturalgasAlarmin.STATION_ID,naturalgasAlarmin.getStationId());
                }
        return entityWrapper;
        }
        }
